// Create Process to run exe
// Date 19:40 24/10/2016
// By Ben a.k.a DreamVB

#include <iostream>
#include <Windows.h>
using namespace std;
using std::cout;
using std::endl;

bool RunMyApp(char *program){
	BOOL IsGood;
	PROCESS_INFORMATION pi;
	STARTUPINFOA si;

	if (strlen(program) == 0){
		return false;
	}

	//Setup STartup info
	memset(&si, 0, sizeof(si));
	si.cb = sizeof(si);

	//Try and execute the program.
	IsGood = CreateProcessA(NULL, program,
		NULL, NULL, FALSE,
		0, NULL, NULL, 
		&si, &pi);

	if (IsGood){
		//Close open handles
		CloseHandle(pi.hThread);
		CloseHandle(pi.hProcess);
	}
	return IsGood;
}

int main(int argc, char *argv[]){
	char program[5][MAX_PATH];
	int op = 0;

	//Add program exe names
	strcpy(program[0], "calc.exe");
	strcpy(program[1], "notepad.exe");
	strcpy(program[2], "c:\\Program Files (x86)\\Winamp\\winamp.exe");
	strcpy(program[3], "mspaint.exe");

	do{
		system("cls");
		cout << "-------------------" << endl;
		cout << "+    App Menu     +" << endl;
		cout << "-------------------" << endl;
		cout << " [1] Calulator" << endl;
		cout << " [2] Notepad" << endl;
		cout << " [3] Command Prompt" << endl;
		cout << " [4] MsPaint" << endl;
		cout << " [5] Quit" << endl;
		cout << "-------------------" << endl;
		cout << "Enter a choice : ";
		cin >> op;

		switch (op){
		case 1:
			RunMyApp(program[0]);
			break;
		case 2:
			RunMyApp(program[1]);
			break;
		case 3:
			RunMyApp(program[2]);
			break;
		case 4:
			RunMyApp(program[3]);
			break;
		}
	} while (op != 5);

	system("pause");
	return 0;
}